home *** CD-ROM | disk | FTP | other *** search
/ Game Programming in C++ - Start to Finish / GameProgrammingS.iso / Peon / PeonSDK-Win32-1.0.0.exe / {app} / PeonMain / include / SceneRenderer.h < prev    next >
Encoding:
C/C++ Source or Header  |  2005-11-25  |  6.5 KB  |  228 lines

  1.  
  2. #ifndef __SCENERENDERER_H_
  3. #define __SCENERENDERER_H_
  4. /*
  5. Peon - Win32 Games Programming Library
  6. Copyright (C) 2002-2005 Erik Yuzwa
  7.  
  8. This library is free software; you can redistribute it and/or
  9. modify it under the terms of the GNU Library General Public
  10. License as published by the Free Software Foundation; either
  11. version 2 of the License, or (at your option) any later version.
  12.  
  13. This library is distributed in the hope that it will be useful,
  14. but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  16. Library General Public License for more details.
  17.  
  18. You should have received a copy of the GNU Library General Public
  19. License along with this library; if not, write to the Free
  20. Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  21.  
  22. Erik Yuzwa
  23. peon AT wazooinc DOT com
  24. */
  25.  
  26.  
  27. #include "IUnknown.h"
  28. #include "PrimTypes.h"
  29. #include "SceneCamera.h"
  30. #include "SceneLight.h"
  31. #include "SceneTexture.h"
  32. #include "SceneFont.h"
  33. #include "Matrix44.h"
  34.  
  35. /** our maximum lights allowed at one time in our engine. OpenGL allows
  36. * 7 if I remember right, and Direct3D allows something similar. New hardware
  37. * might blow these boundaries away through shaders, but let's pretend you 
  38. * can only use 7
  39. */
  40. #define MAX_LIGHTS 7
  41.  
  42. namespace peon
  43. {
  44.     /**
  45.     * This object is responsible for processing our rendering commands
  46.     * to the underlying video hardware. Rather than spread a whole bunch
  47.     * of API specific code in our actual game, it'd be nice to just command
  48.     * this object to do the work for us.
  49.     */
  50.     class PEONMAIN_API SceneRenderer : public IUnknown
  51.     {
  52.     protected:
  53.         /** OpenGL rendering surface */
  54.         SDL_Surface*        m_pOGLSurface;
  55.  
  56.         /** surface width */
  57.         int                    m_iDeviceWidth;
  58.  
  59.         /** surface height */
  60.         int                    m_iDeviceHeight;
  61.  
  62.         /** surface bits-per-pixel */
  63.         int                    m_iBitsPerPixel;
  64.  
  65.         /** windowed or fullscreen? */
  66.         bool                m_bWindowed;
  67.  
  68.         /** our current SceneCamera object */
  69.         SceneCamera*            m_pActiveCamera;
  70.  
  71.         /** an array of SceneLight objects. */
  72.         SceneLight                m_oLights[MAX_LIGHTS];
  73.  
  74.     public:
  75.         /**
  76.         * Constructor
  77.         */
  78.         SceneRenderer();
  79.  
  80.         /**
  81.         * Destructor
  82.         */
  83.         ~SceneRenderer();
  84.  
  85.         /**
  86.         * This method loads our configuration settings in order to prepare
  87.         * our rendering context
  88.         * @param pConfig - IniConfigReader object
  89.         * @return bool - true or false
  90.         */
  91.         bool loadDevice( IniConfigReader* pConfig );
  92.  
  93.         /**
  94.         * This method deallocated and cleans up our surfaces 
  95.         */
  96.         void unloadDevice();
  97.         
  98.         /**
  99.         * This method clears the back buffer and prepares it for us
  100.         * to send rendering commands to
  101.         * @return bool - always true
  102.         */
  103.         bool clearDevice();
  104.  
  105.         /**
  106.         * This method is responsible for swapping our back buffer with
  107.         * the front one...thereby rendering a new screen
  108.         */
  109.         void flipDevice();
  110.  
  111.         /**
  112.         * This method takes in an array of vertices and renders them to
  113.         * our context
  114.         * @param pVertices - array of DiffusePrim objects
  115.         * @param count     - count of DiffusePrim objects in array
  116.         */
  117.         void drawPrim( DiffusePrim* pVertices, int count );
  118.  
  119.         /**
  120.         * This method takes in an array of vertices and renders them to
  121.         * our context
  122.         * @param pVertices - array of DiffuseTexPrim objects
  123.         * @param count     - count of DiffuseTexPrim objects in array
  124.         */
  125.         void drawPrim( DiffuseTexPrim* pVertices, int count );
  126.  
  127.         /**
  128.         * This method takes in an array of vertices and renders them to
  129.         * our context
  130.         * @param pVertices - array of NormalDiffuseTexPrim objects
  131.         * @param count     - count of NormalDiffuseTexPrim objects in array
  132.         */
  133.         void drawPrim( NormalDiffuseTexPrim* pVertices, int count );
  134.  
  135.         /**
  136.         * This method takes in an array of vertices and renders them to
  137.         * our context
  138.         * @param pVertices - array of NormalDiffuseTexPrim objects
  139.         * @param count     - count of NormalDiffuseTexPrim objects in array
  140.         */
  141.         void drawQuads( NormalDiffuseTexPrim* pVertices, int count );
  142.  
  143.         /**
  144.         * This method simply sets a set of lighting states within our
  145.         * scene depending upon the parameters 
  146.         * @param light_slot - which slot we wish to affect
  147.         * @param oLight     - our SceneLight object
  148.         */
  149.         void setLight(int light_slot, const SceneLight& oLight);
  150.  
  151.         /**
  152.         * This method is responsible for loading an image into
  153.         * the texture memory of your device
  154.         * @param strFilename - the path to the image file
  155.         * @param bAlpha - do we have an alpha channel?
  156.         * @param bMipMaps - do we create mipmaps?
  157.         * @param bRepeat - do we repeat the texture?
  158.         * @return SceneTexture* - pointer to the created SceneTexture object
  159.         */
  160.         SceneTexture* loadTexture( const String& strFilename, bool bAlpha = true,
  161.             bool bMipMaps = true, bool bRepeat = false);
  162.  
  163.         /**
  164.         * This method just informs the renderer to make this texture the 
  165.         * currently active one
  166.         * @param pTex - pointer to our SceneTexture handle
  167.         */
  168.         //void setTexture( SceneTexture* pTex );
  169.  
  170.         /**
  171.         * This method is responsible for loading a font object into a 
  172.         * SceneFont handle
  173.         * @param char_width - pixel width of each character
  174.         * @param char_height - pixel height of each character
  175.         * @param char_spacing - spacing in pixels between character
  176.         * @return SceneFont* - handle to our created SceneFont
  177.         */
  178.         SceneFont* loadFont( int char_width = 16, int char_height = 16, int char_spacing = 10 );
  179.  
  180.         /**
  181.         * This method just returns our active camera
  182.         * @return SceneCamera* - handle to our SceneCamera
  183.         */
  184.         SceneCamera* getActiveCamera(){ return m_pActiveCamera; }
  185.  
  186.         /**
  187.         * Gets the width of our device
  188.         * @return int - device width 
  189.         */
  190.         int getWidth(){ return m_iDeviceWidth; }
  191.  
  192.         /**
  193.         * Gets the height of our device
  194.         * @return int - device height
  195.         */
  196.         int getHeight(){ return m_iDeviceHeight; }
  197.  
  198.         /**
  199.         * Check to see if an extension is supported
  200.         * @param strExtension - string object containing extension name
  201.         * @return bool - true if it does, false otherwise
  202.         */
  203.         bool isExtensionSupported( const String& strExtension );
  204.  
  205.         /**
  206.         * This method is responsible for taking screen captures
  207.         */
  208.         void getScreenCapture();
  209.  
  210.         /**
  211.         * This method simply fills a Matrix44 object with the current
  212.         * projection matrix
  213.         * @param pMat - handle to our Matrix44 object
  214.         */
  215.         void getProjectionMatrix( Matrix44& pMat );
  216.         
  217.         /**
  218.         * This method simply fills a Matrix44 object with the current
  219.         * modelview matrix
  220.         * @param pMat - handle to our Matrix44 object
  221.         */
  222.         void getModelViewMatrix( Matrix44& pMat );
  223.     
  224.     };
  225. }
  226.  
  227. #endif
  228.